package zhiyou100.session;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;

//@WebServlet("/getSession.action")
public class GetSessionServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 设置响应的文本类型
        response.setContentType("text/html;charset=UTF-8");
        // 获取session值
        HttpSession session = request.getSession();// 有，就直接获取
        String username = (String) session.getAttribute("username");
        // request 域对象
        if (username != null) {
            // 把获取到的session值输出在客户端页面上
            response.getWriter().write(username);
            return;
        }
        response.getWriter().write("session中没有值");
    }

}
